<template>
  <div class="container">
    <div class="weui_cells_title">诊疗号：</div>
    <div class="weui_cells weui_cells_access" style="margin-top:10px;">
      <a @click="selectCard" class="weui_cell" href="javascript:;">
        <div class="weui_cell_hd">
          <i class="fa fa-credit-card fa-2x icon-color" style="width:45px;margin-right:5px;display:block;"></i>
        </div>
        <div class="weui_cell_bd weui_cell_primary">
          <p>{{card?card.name:''}}</p>
          <p>{{card?card.num:''}}</p>
        </div>
        <div class="weui_cell_ft">
          选诊疗号
        </div>
      </a>
    </div>
    <div>
      <div class="weui_cells_title">
        <p class="am-ft-sm am-ft-gray">
          <span class="am-ft-orange"><i class="fa fa-info-circle"></i></span> 只支持查询挂号日期起15日内的挂号
        </p>
      </div>
      <div class="weui_cells weui_cells_access weui_cells_form">
        <div class="weui_cell">
          <div class="weui_cell_hd">
            <label class="weui_label">挂号日期</label>
          </div>
          <div class="weui_cell_bd weui_cell_primary">
            <input class="weui_input" type="date" v-model="startDate">
          </div>
          <div class="weui_cell_ft">
          </div>
        </div>
      </div>
    </div>
    <div class="weui_cells_title" v-show="showEmpty">{{emptyMsg}}</div>
    <div class="weui_cells weui_cells_access ft-sm" style="margin-top:10px;">
      <a v-for="regInfo in regInfos" class="weui_cell" href="javascript:;">
       <!--  <div class="weui_cell_hd">
          <i class="fa fa-file-text-o fa-2x icon-color" style="width:35px;margin-right:5px;display:block;"></i>
        </div> -->
        <div class="weui_cell_bd weui_cell_primary">
          <p>班次时间：<span class="am-ft-sm am-ft-blue">{{regInfo.startTime.substr(0,10)}} {{regInfo.startTime.substr(11,5)}} - {{regInfo.endTime.substr(11,5)}}</span></p>
          <p>科室：<span class="am-ft-sm am-ft-blue">{{regInfo.deptName}}</span></p>
          <p v-show="regInfo.doctorName">医生：<span class="am-ft-sm am-ft-blue">{{regInfo.doctorName}}</span></p>
          <p>挂号类型：<span class="am-ft-sm am-ft-blue">{{regInfo.regType}}</span></p>
          <p>挂号费：<span class="am-ft-sm am-ft-blue">{{regInfo.regAmt}}</span></p>
          <p>挂号时间：<span class="am-ft-sm am-ft-blue">{{regInfo.regTime}}</span></p>
          <p>挂号排队号：<span class="am-ft-sm am-ft-blue">{{regInfo.waitNo}}</span></p>
          <p>状态：<span class="am-ft-sm am-ft-blue">{{regInfo.state}}</span></p>
        </div>
      </a>
    </div>
    <partial name="footer-copyright"></partial>
  </div>
</template>
<style scoped>
.ft-sm p {
  padding: 3px;
  font-size: 12px;
}

.blue_tag {
  background-color: #0ae;
  color: #fff;
  font-size: 13px;
  padding: 2px 4px;
  border: none;
  vertical-align: middle;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  border-radius: 3px;
}

.orange_tag {
  background-color: #ff8208;
  color: #fff;
  font-size: 13px;
  padding: 2px 4px;
  border: none;
  vertical-align: middle;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  border-radius: 3px;
}
</style>
<script>
import { commonUtil } from '../../plugins/common'
import _ from 'underscore'

export default {
  name: 'SearchRegInfoView',
  data: function () {
    return {
      startDate: '',
      regInfos: [],
      showEmpty: false,
      emptyMsg: ''
    }
  },
  vuex: {
    getters: {
      card: ({ card }) => _.findWhere(card.cards, { isSelected: true })
    }
  },
  ready: function () {
    this.startDate = commonUtil.getDateStr(-15)

    this.$watch('startDate', function (val) {
      this.getRegInfos()
    })

    this.$watch('card', function (val) {
      this.getRegInfos()
    })

    this.getRegInfos()
  },
  methods: {
    selectCard: function () {
      this.$router.go({ name: 'selectCard' })
    },
    getRegInfos: function () {
      if (!this.card || this.startDate === '') {
        return
      }
      this.showEmpty = false

      var self = this

      this.$ajax.get('GetRegInfo', 'Reg', {
        cardNo: this.card.num,
        startDate: this.startDate
      }).then(function (data) {
        if (data.ResultCode !== '0') {
          self.showEmpty = true
          self.emptyMsg = data.ResultMsg
          self.regInfos = []
        } else {
          self.regInfos = _.map(data.RegInfos, function (val) {
            return {
              deptName: val.DeptName,
              doctorName: val.DoctorName,
              regType: val.RegType,
              regAmt: val.RegAmt,
              startTime: val.StartTime,
              endTime: val.EndTime,
              regTime: val.RegTime,
              waitNo: val.WaitNo,
              state: val.State
            }
          })

          if (self.regInfos.length <= 0) {
            self.showEmpty = true
            self.emptyMsg = '找不到挂号记录'
            self.regInfos = []
          }
        }
      })
    }
  }
}
</script>
